<template>
    <div>
    <!-- 顶部滑动条区域 -->
    <div id="slider" class="mui-slider">
      <div id="sliderSegmentedControl" class="mui-scroll-wrapper mui-slider-indicator mui-segmented-control mui-segmented-control-inverted">
        <div class="mui-scroll">
          <a :class="['mui-control-item', item.id == 0 ? 'mui-active' : '']"
           v-for="item in cates" :key="item.id"
            @click="getPhotoListByCateId(item.id)">
            {{ item.title }}
          </a>
        </div>
      </div>
    </div>
    <!-- 图片列表区域 -->
    <ul class="phoneList">
        <router-link v-for="item in list"  :key="item.id" :to="'/home/photoInfo/'+item.id" tag="li">
            <img v-lazy="item.img_url">
        </router-link>
    </ul>

    </div>    
</template>

<script>

// import mui from "../../lib/mui/js/mui.js"
// import mui from "../../lib/mui/js/mui.min.js";

    export default {
        data(){
            return {
                cates:[],
                list:[]
            }
        },
        created(){
            this.getimgcategory()
            this.getPhotoListByCateId(0)
        },
        mounted(){
    //          mui(".mui-scroll-wrapper").scroll({
    //         deceleration: 0.0005 //flick 减速系数，系数越大，滚动速度越慢，滚动距离越小，默认值0.0006
    // });
        },
        methods:{
            getimgcategory(){
                this.$http.get('http://127.0.0.1:5000/api/getimgcategory').then(result=>{
                    if (result.body.status === 0) {
                           // 手动拼接出一个最完整的 分类列表
                        result.body.message.unshift({ title: "全部", id: 0 });
                        this.cates = result.body.message;
                    }
                })
            },
            getPhotoListByCateId(imgid){
                // console.log(imgid);
                
                this.$http.get('http://127.0.0.1:5000/api/getimages/'+imgid).then(result=>{
                this.list = result.body.message;
                console.log(result);
                    
                })
            }
        }
    }
</script>

<style lang="scss" scoped>
    *{
        touch-action: pan-y;
       
    }
    .phoneList{
        margin:0;
        padding:10px;
        background-color: #ccc;
        list-style: none;

        li{
            text-align: center;        
            margin-bottom: 10px;
            margin-top: 10px;
    
            img{
                width: 100%;
            }
        }
    }
    img[lazy=loading]{
        width: 40px;
        height: 300px;
        margin:auto;
    }
</style>

